The PHP function error_reporting of E_ALL ^ E_NOTICE

  • 2020-05-09 18:21:08
  • OfStack

Examples:

In the environment of Windows: the program that normally runs in php4.3.0, why many errors are reported in 4.3.1, the general prompt is: Notice:Undefined varialbe: variable name.
For example, have the following code:
 
if (!$tmp_i) { 
$tmp_i=10; 
} 

Running normally in 4.3.0, running in 4.3.1 will prompt Notice:Undefined varialbe:tmp_i
The following questions:
1. What's the problem?
2. How should I modify this code?
3. How to modify the Settings in php.ini so that the program in 4.3.0 runs normally under 4.3.1 without changing the code? This error does not appear.

Solutions:

Add a sentence at the beginning of the program:
error_reporting (E_ALL & ~ E_NOTICE); Or error_reporting (E_ALL ^ E_NOTICE);

or
Modify php ini
error_reporting = E_ALL & ~E_NOTICE

About the error_reporting() function:


error_reporting() sets the error reporting level of PHP and returns the current level.

; Error reporting is bitwise. Or add the Numbers together to get the desired error reporting level.
; E_ALL - all errors and warnings
; E_ERROR - fatal runtime error
; E_WARNING - runtime warning (non-fatal error)
; E_PARSE - compile-time parsing error
; E_NOTICE - runtime reminders (these are often caused by the bug of your code,

; Or it could be a deliberate act. (e.g., based on uninitialized variables automatically initialized to 1
; Empty string facts while using 1 uninitialized variable)

; E_CORE_ERROR - fatal error during initialization at startup of PHP
; E_CORE_WARNING - warning during initialization at PHP startup (non-fatal error)
; E_COMPILE_ERROR - fatal error at compile time
; E_COMPILE_WARNING - compile-time warning (non-fatal error)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated reminder message

Usage:

error_reporting (0); // disable error reporting
error_reporting (E_ALL ^ E_NOTICE); // displays all error messages except E_NOTICE
error_reporting (E_ALL ^ E_WARNING ^ E_NOTICE); // displays all error messages except E_WARNING E_NOTICE
error_reporting(E_ERROR | E_WARNING | E_PARSE); // display runtime error, error_reporting(E_ALL ^ E_NOTICE); The effect is the same. error_reporting (E_ALL); // displays all errors

Related articles: